package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitemwlmq;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitemwlmq.vo.DpItemWlmqPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitemwlmq.vo.DpItemWlmqRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitemwlmq.vo.DpItemWlmqSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dpitem.DpItemWlmqDO;
import cn.iocoder.yudao.module.erp.service.dpitem.DpItemWlmqService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - ERP乌鲁木齐制单货号详情")
@RestController
@RequestMapping("/erp/dp-item-wlmq")
@Validated
public class DpItemWlmqController {

    @Resource
    private DpItemWlmqService dpItemWlmqService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP乌鲁木齐制单货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wlmq:create')")
    public CommonResult<Long> createDpItemWlmq(@Valid @RequestBody DpItemWlmqSaveReqVO createReqVO) {
        return success(dpItemWlmqService.createDpItemWlmq(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP乌鲁木齐制单货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wlmq:update')")
    public CommonResult<Boolean> updateDpItemWlmq(@Valid @RequestBody DpItemWlmqSaveReqVO updateReqVO) {
        dpItemWlmqService.updateDpItemWlmq(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP乌鲁木齐制单货号详情")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wlmq:delete')")
    public CommonResult<Boolean> deleteDpItemWlmq(@RequestParam("id") Long id) {
        dpItemWlmqService.deleteDpItemWlmq(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP乌鲁木齐制单货号详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wlmq:query')")
    public CommonResult<DpItemWlmqRespVO> getDpItemWlmq(@RequestParam("id") Long id) {
        DpItemWlmqDO dpItemWlmq = dpItemWlmqService.getDpItemWlmq(id);
        return success(BeanUtils.toBean(dpItemWlmq, DpItemWlmqRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP乌鲁木齐制单货号详情分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wlmq:query')")
    public CommonResult<PageResult<DpItemWlmqRespVO>> getDpItemWlmqPage(@Valid DpItemWlmqPageReqVO pageReqVO) {
        PageResult<DpItemWlmqDO> pageResult = dpItemWlmqService.getDpItemWlmqPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpItemWlmqRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP乌鲁木齐制单货号详情 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wlmq:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpItemWlmqExcel(@Valid DpItemWlmqPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpItemWlmqDO> list = dpItemWlmqService.getDpItemWlmqPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP乌鲁木齐制单货号详情.xls", "数据", DpItemWlmqRespVO.class,
                        BeanUtils.toBean(list, DpItemWlmqRespVO.class));
    }

}